﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Globalization;
using System.ComponentModel;
using System.Data;
using System.IO;
using System.Text;

namespace Texfina.Core.Web
{
   [ToolboxData("<{0}:esdFilter Runat=server></{0}:esdFilter>")]
   public class esdFilter : WebControl
   {
      //private ScriptManager sm;

      [DefaultValue(FilterType.esdDateTexbox)]
      public FilterType FilterType
      {
         get
         {
            if (this.ViewState["_filType"] == null)
               return FilterType.esdDateTexbox;
            else
               return (FilterType)this.ViewState["_filType"];
         }
         set { this.ViewState["_filType"] = value; }
      }

      [DefaultValue("")]
      public string Title
      {
         get
         {
            if (this.ViewState["_title"] == null)
               return "";
            else
               return (string)this.ViewState["_title"];
         }
         set { this.ViewState["_title"] = value; }
      }

      [DefaultValue("")]
      public DataTable DataSourceList
      {
         get
         {
            if (this.ViewState["_dtl"] == null)
               return null;
            else
               return (DataTable)this.ViewState["_dtl"];
         }
         set { this.ViewState["_dtl"] = value; }
      }

      [System.Security.Permissions.PermissionSet(System.Security.Permissions.SecurityAction.Demand, Name = "FullTrust")]
      protected override void RenderContents(HtmlTextWriter writer)
      {

         TextWriter RenderHtml = new StringWriter();
         RenderHtml.Write("<div id=\"" + this.ID + "Content" + "\" style=\" width:100%; height:100%;\">");
         RenderHtml.Write("   <a href=\"#\" id=\"" + this.ID + "href" + "\">" + this.Title + "</a>");
         RenderHtml.Write("      <div id=\"" + this.ID + "\" title=\"" + this.Title + "\">");
         RenderHtml.Write("         <select id=\"" + this.ID + "Operador" + "\" style=\" width:100%;\" >");
         RenderHtml.Write("            <option value=\"like\">Contiene</option>");
         RenderHtml.Write("            <option value=\"=\">Igual que</option>");
         RenderHtml.Write("            <option value=\">\">Menor que</option>");
         RenderHtml.Write("            <option value=\">=\">Menor Igual que</option>");
         RenderHtml.Write("            <option value=\"<\">Mayor que</option>");
         RenderHtml.Write("            <option value=\"<=\">Mayor Igual que</option>");
         RenderHtml.Write("         </select>");
         RenderHtml.Write("         <br/>");
         RenderHtml.Write("         <br/>");
         switch (FilterType)
         {
            case FilterType.esdDateTexbox:

               RenderHtml.Write("<input type=\"text\" id=\"" + this.ID + "Text" + "\" name=\"" + this.ID + "Text" + "\" class=\"esdTextBox\" style=\" width:294px;\" />");
               
               break;
            
            case FilterType.esdDropDownList:
               RenderHtml.Write("         <select style=\" width:100%;\" >");
               if (this.DataSourceList != null && this.DataSourceList.Columns.Contains("dsDescrip") && this.DataSourceList.Columns.Contains("idCodigo"))
               {
                  foreach (DataRow dr in this.DataSourceList.Rows)
                  {
 
                  }

               }

               RenderHtml.Write("         </select>");
               break;
            case FilterType.esdTextBox:
               break;
         }
         RenderHtml.Write("         <br/>");
         RenderHtml.Write("         <br/>");
         RenderHtml.Write("<input type=\"button\" value=\"Agregar Filtro\" id=\"" + this.ID + "Button" + "\" name=\"" + this.ID + "Button" + "\" class=\"esdButtonStyle\" style=\" width:296px;\" onclick=\"AddFilter('" + this.ID + "Operador','" + this.ID + "Text');\" />");
              
         RenderHtml.Write("      </div>");
         RenderHtml.Write("</div>");

         writer.Write(RenderHtml.ToString());
      }

   }
}
